<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/jquery-3.1.1.min.js"></script>
</head>
<body>
<h3>用户修改头像</h3>
<form id="rephotoForm">
    <p>
        <input type="hidden" name="id" value="9"/>
        <input type="file" name="userphoto" />
    </p>
    <p><button type="button" id="upSureBtn">修改头像</button> </p>
    <img width="100" height="100" id="showPhoto" alt="用户头像" />
</form>
<script>
    $(function(){
        $("#upSureBtn").click(function(){
            $.ajax({
                type : 'post' ,
                url : 'http://localhost:8500/sys/user/rephoto' ,
                data : new FormData($("#rephotoForm")[0]) ,
                contentType : false , // 不使用默认类型: "application/x-www-form-urlencoded"
                processData : false ,  // 不要把data数据转为String
                success : function(req) {
                    if(200 == req.errorCode) {
                        $("#showPhoto").attr('src' , req.data)
                    } else {
                        alert('上传失败!')
                    }
                }
            })
        })
    })
</script>
</body>
</html>